var webpack = require('webpack');
var path = require("path");
var packageJSON = require('./package.json');

const ENV  = process.env.NODE_ENV;
console.log('Build environment is ' + ENV);
var config = {
  entry: {
    'q': './src/index.js'
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: '[name].js',
    library: 'q',
    libraryTarget: 'umd'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        include: [
          path.resolve(__dirname, "src")
        ],
        options: {
            "plugins": [
                "transform-runtime"
            ],
            "presets": ["es2015"] 
        }
      }
    ]
  },
  plugins: [
    new webpack.BannerPlugin(packageJSON.name
      + " v"+ packageJSON.version
      + "\r\nauthor "+ packageJSON.author)
  ],
  devtool: "#source-map"
};
if(ENV === "build-min" || ENV === "build-light") {
  config.plugins.push(new webpack.optimize.UglifyJsPlugin({
    compress: {
      warnings: false
    }
  }));

  if(ENV === "build-min") {
    config.entry = {
        'q.min': './src/index.js'
    };
  } else {
    config.entry = {
        'q.light': './src/index.js'
    };
    config.module.rules[0].options.plugins[0] = ["transform-runtime", {"polyfill": false}];
  }
  
}

module.exports = config;
